package br.senac.arqpad.pizzaria.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import br.senac.arqpad.pizzaria.model.Ingrediente;

public class IngredienteDAOJDBC extends DAOJDBC<Ingrediente> {

	@Override
	protected String obterQueryListarTodos() {
		return "SELECT id, nome, descricao, medida FROM Ingrediente";
	}

	@Override
	protected String obterQueryObter() {
		return obterQueryListarTodos() + " WHERE id = ?";
	}

	@Override
	protected String obterQueryUpdate() {
		return "UPDATE Ingrediente SET nome=?, descricao=?, medida=? WHERE id = ?;";
	}

	@Override
	protected String obterQueryDelete() {
		return "DELETE FROM Ingrediente WHERE id = ?;";
	}

	@Override
	protected String obterQueryInsert() {
		return "INSERT INTO Ingrediente (nome, descricao, medida) VALUES (?, ?, ?);";
	}

	@Override
	protected PreparedStatement preencheParametrosObter(Ingrediente item,
			PreparedStatement preparedStatement) throws SQLException {
		preparedStatement.setLong(1, (Long) item.getId());
		return preparedStatement;
	}

	@Override
	protected Ingrediente montaObjeto(ResultSet rs) throws SQLException {
		
		Ingrediente item = new Ingrediente();
		
		item.setId(rs.getLong("id"));
		item.setNome(rs.getString("nome"));
		item.setDescricao(rs.getString("descricao"));
		item.setMedida(rs.getString("medida"));
		
		return item;
	}

	@Override
	protected PreparedStatement preencheParametrosInsert(Ingrediente item,
			PreparedStatement preparedStatement) throws SQLException {
		preparedStatement.setString(1, item.getNome());
		preparedStatement.setString(2, item.getDescricao());
		preparedStatement.setString(3, item.getMedida());	
		return preparedStatement;
	}

	@Override
	protected PreparedStatement preencheParametrosUpdate(Ingrediente item,
			PreparedStatement preparedStatement) throws SQLException {
		preparedStatement.setString(1, item.getNome());
		preparedStatement.setString(2, item.getDescricao());
		preparedStatement.setString(3, item.getMedida());
		preparedStatement.setLong(4, (Long) item.getId());
		return preparedStatement;
	}

}
